//
//  HotTableViewCell.m
//  PTravel
//
//  Created by dllo on 15/11/15.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "HotTableViewCell.h"

@implementation HotTableViewCell

- (void)dealloc
{
    [_image release];
    [_userLabel release];
    [_lookNumLabel release];
    [_discussLabel release];
    [_lookImage release];
    [_discussImage release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    //图片
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(2, 5, 100, 80)];
    [self.contentView addSubview:self.image];
    [_image release];
    
    //标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x+125, 5, BOUNDS.size.width-(self.image.frame.origin.x+125)-2, 38)];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.numberOfLines = 0;
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    //作者
    self.userLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x+125, self.image.frame.origin.y+40, BOUNDS.size.width-(self.image.frame.origin.x+125), 15)];
    self.userLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.userLabel];
    [_userLabel release];
    
    //浏览图片
    self.lookImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.image.frame.origin.x+125, self.userLabel.frame.origin.y+20, 15, 15)];
    self.lookImage.image = [UIImage imageNamed:@"lookImage"];
    [self.contentView addSubview:self.lookImage];
    [_lookImage release];
    
    //浏览数目
    self.lookNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x+140, self.userLabel.frame.origin.y+20, 45, 15)];
    self.lookNumLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.lookNumLabel];
    [_lookNumLabel release];
    
    //评论图片
    self.discussImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.image.frame.origin.x+200, self.userLabel.frame.origin.y+20, 15, 15)];
    self.discussImage.image = [UIImage imageNamed:@"iconfont-pinglun.png"];
    [self.contentView addSubview:self.discussImage];
    [_discussImage release];
    
    //评论数目
    self.discussLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x+215, self.userLabel.frame.origin.y+20, 45, 15)];
    self.discussLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.discussLabel];
    [_discussLabel release];
    
}

- (void)setHotTravel:(HotTravel *)hotTravel
{
    if (_hotTravel != hotTravel) {
        [_hotTravel release];
        _hotTravel = [hotTravel retain];
    }
    self.titleLabel.text = hotTravel.title;
    self.userLabel.text = hotTravel.username;
    self.lookNumLabel.text = [NSString stringWithFormat:@"%ld", hotTravel.views];
    self.discussLabel.text = hotTravel.replys;
    NSURL *url = [NSURL URLWithString:hotTravel.photo];
    [self.image sd_setImageWithURL:url placeholderImage:IMAGE];
    self.titleLabel.textColor = [Night textColor];
    self.userLabel.textColor = [Night textColor];
    self.lookNumLabel.textColor = [Night textColor];
    self.discussLabel.textColor = [Night textColor];

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
